
//点击提交
$().ready(function () {
    //检测手机号是否正确
    jQuery.validator.addMethod("isMobile", function (value, element) {
        var length = value.length;
        var regPhone = /^1([3578]\d|4[57])\d{8}$/;
        return this.optional(element) || ( length == 11 && regPhone.test(value) );
    }, "请正确填写您的手机号码");
//检测用户姓名是否为汉字
//    jQuery.validator.addMethod("isChar", function (value, element) {
//        var length = value.length;
//        var regName = /[^\u4e00-\u9fa5]/g;
//        return this.optional(element) || !regName.test(value)
//    }, "请输入中文姓名");

   var id = sessionStorage.getItem('id');
    var username = sessionStorage.getItem('username');
   var phone = sessionStorage.getItem('phone');
    var techway = sessionStorage.getItem('techway');
    $('#myform').validate({

        rules: {
            username: {
                required: true,
                minlength: 2,
                //isChar: true,
            },
            phone: {
                required: true,
                isMobile: true,
            }
        },
        messages: {
            username: {
                required: '请输入姓名',
                minlength: '姓名输入至少2字符',
                //isChar: '请输入中文姓名',
            },
            phone: {
                required: '请输入手机号码',
                isMobile: '请正确填写您的手机号码',
            }
        },
        submitHandler: function (form) {

            $.ajax({
                url: url + 'yuyue',
                type: 'post',
                dataType: 'json',
                async: 'false',
                data: {'techid':id,'stuname':username,'stuphone':phone,'techway':techway},
                timeout: 2000,
                success: function (data) {
                    var code = data.code;
                    var status = data.status;
                    var message = data.data;
                    if (code == 1002 && status == 1) {
                        alert(message);
                    }else if(code == 1003 && status == 1){
                        alert(message);
                    }else {
                        alert(message);
                    }
                },
                error: function (data) {
                    console.log('提交失败');
                }
            })
        },
        invalidHandler: function (form, validator) {
            alert('提交失败');
            return false;
        }
    });
});